import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { HttpProvider } from '../../providers/http/http';
import { StorageProvider } from '../../providers/storage/storage';
import { DialogProvider } from '../../providers/dialog/dialog';
import { UnitsProvider } from '../../providers/units/units';
/**
 * Generated class for the AssistantchuchaiPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-assistantchuchai',
  templateUrl: 'assistantchuchai.html',
})
export class AssistantchuchaiPage {

    /**
	 * 输入界面控制
	 */
  inputSelectView = {
    applyoaminDate: '',
    applyoamaxDate: '',
  }

 /**
	 * 输入界面控制
	 */
  inputViewModel = {
    applyapplymember: '', //姓名
    applytime: '', //出差日期
    applycompany: new Object(), //申请公司
    applydepartment: new Object(), //申请部门
    applychangenote: '', //出差事由
    applyholidaystarttime: '', //开始时间
    applyholidayendtime: '', //结束时间
    applyholidaydays: '', //出差天数
    applyholidayaddress: '', //出差地点
    applyholidayload: '', //出差路线
    applyholidaytool: '', //交通工具
    applyholidayair: '', //乘坐飞机事由
    applyholidayamountmin: '', //借支差旅费金额-小写
    applyholidayamountmax: '', //借支差旅费金额-大写
    applynote: '', //备注
    applynownode: '', //当前节点
    applynowmember: '', //当前处理人
    applynextnode: '', //下一步审批节点
    applynextman: '', //下一步审批人
  }

  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    public http: HttpProvider,
    public storage: StorageProvider,
    public dialog: DialogProvider,
    public units: UnitsProvider) {
    this.inputSelectView.applyoaminDate = '2010-01-01';
    this.inputSelectView.applyoamaxDate = this.units.getinitDate();
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad AssistantchuchaiPage');
    this.ionicLoad();
  }
  //当前节点
  ionicLoad() {
    //控制显示
    this.getUserInfo();
    this.inputViewModel.applytime = this.units.getCurrentDate(new Date().getTime());
    this.inputViewModel.applynownode = '提交申请'; //当前节点
    this.inputViewModel.applynextnode = '部门内控办理'; //当前节点
  }
    //获取本用户信息
    getUserInfo() {
      this.storage.getStorage("user").then(val => {
        //请求方式如下
        let params = {
          user_id: val['user_id']
        };
        this.http.postJson('user', 'douserinfo.do', params).then(res => {
          if (res['success'] == true) {
            let info = res['data'];
            //请求成功
            this.inputViewModel.applyapplymember = info['name'];
            this.inputViewModel.applynowmember = info['name'];
          } else {
            this.dialog.showToast("top", res['msg']);
          }
        });
      });
    }
     //初始化选择公司
  applycompanyselect() {
    //共通弹出
    let data = new Object();
    data['selectitem'] = this.inputViewModel.applycompany;
    data['multiselect'] = false; //false 单选 true 多选
    let opts = new Object();
    this.dialog.showModal("ModalcompanyselectPage", data, opts).then(success => {
      //界面关闭的时候
      if (success) {
        let result = success['result'];
        this.inputViewModel.applycompany = result[0];
      }
    });
  }
  //初始化选择部门
  applydepartselect() {
    //共通弹出
    let data = new Object();
    data['selectitem'] = this.inputViewModel.applydepartment;
    data['multiselect'] = false; //false 单选 true 多选
    let opts = new Object();
    this.dialog.showModal("ModaldepartselectPage", data, opts).then(success => {
      //界面关闭的时候
      if (success) {
        let result = success['result'];
        this.inputViewModel.applydepartment = result[0];
      }
    });
  }
  //初始化选择用户
  applyapplymemberselect() {
    //共通弹出
    let data = new Object();
    data['selectitem'] = this.inputViewModel.applynextman;
    data['multiselect'] = false; //false 单选 true 多选
    let opts = new Object();
    this.dialog.showModal("ModaluserselectPage", data, opts).then(success => {
      //界面关闭的时候
      if (success) {
        let result = success['result'];
        this.inputViewModel.applynextman = result[0];
      }
    });
  }
  //提交数据
  applyapplydone() {
    if (this.checkInput()) {
      //初始化
      this.storage.getStorage("user").then(val => {
        //请求方式如下
        let params = {
          user_id: val['user_id'],
        };
        //收文传阅列表
        this.http.postJson('oa', 'businessTrip/insert.do', params).then(res => {
          if (res['data'] != undefined) {

          } else {

          }
        });
      });
    }
  }

  //检查输入
  checkInput() {

    if (this.inputViewModel.applycompany === "") {
      this.dialog.showToast("top", "请选择申请公司"); return false;
    }
    if (this.inputViewModel.applydepartment === "") {
      this.dialog.showToast("top", "请选择申请部门"); return false;
    }
    if (this.inputViewModel.applychangenote === "") {
      this.dialog.showToast("top", "请输入出差事由"); return false;
    }
    if (this.inputViewModel.applyholidaystarttime === "") {
      this.dialog.showToast("top", "请选择开始时间"); return false;
    }
    if (this.inputViewModel.applyholidayendtime === "") {
      this.dialog.showToast("top", "请选择结束时间"); return false;
    }
    if (this.inputViewModel.applyholidaydays === "") {
      this.dialog.showToast("top", "请输入出差天数"); return false;
    }
    if (this.inputViewModel.applyholidayaddress === "") {
      this.dialog.showToast("top", "请输入出差地点"); return false;
    }
    if (this.inputViewModel.applyholidayload === "") {
      this.dialog.showToast("top", "请输入出差路线"); return false;
    }
    if (this.inputViewModel.applyholidaytool === "") {
      this.dialog.showToast("top", "请输入交通工具"); return false;
    }
    if (this.inputViewModel.applyholidayair === "") {
      this.dialog.showToast("top", "请输入乘坐飞机事由"); return false;
    }
    if (this.inputViewModel.applyholidayamountmin === "") {
      this.dialog.showToast("top", "请输入借支差旅费金额（小写）"); return false;
    }
    if (this.inputViewModel.applyholidayamountmax === "") {
      this.dialog.showToast("top", "请输入借支差旅费金额（大写）"); return false;
    }
    if (this.inputViewModel.applynote === "") {
      this.dialog.showToast("top", "请输入备注"); return false;
    }
    if (this.inputViewModel.applynextman === "") {
      this.dialog.showToast("top", "请选择下一步审批人"); return false;
    }
    return true;
  }
}
